import express from 'express'
import cors from 'cors'
import router from './src/router/serverRouter.js'
import path from 'path'
import { fileURLToPath } from 'url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

const app = express()

app.use(express.json()); // 解析JSON请求体
app.use(express.urlencoded({ extended: true })); // 解析表单请求体

// 启用CORS
app.use(cors())

app.use(router)

app.use('src/assets/images', express.static(path.join(__dirname, 'src', 'assets', 'images'))); // 将静态文件目录设置为 'src/assets/images'


// 启动服务器
const PORT = 3001
app.listen(PORT, '0.0.0.0', () => {
    console.log(`Server running on http://localhost:${PORT}`)
})